package com.sfh.dog.dialog;

import java.util.Calendar;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.widget.DatePicker;

public class Com
{
	/**
	 * 日期选择对话框
	 * 
	 * @param context
	 * @param dateListener
	 * @return
	 */
	public static DatePickerDialog date(Context context, final IDialogData data)
	{
		Calendar calendar = Calendar.getInstance();
		DatePickerDialog dialog = new DatePickerDialog(context,
				new DatePickerDialog.OnDateSetListener()
				{

					@Override
					public void onDateSet(DatePicker arg0, int year, int month,
							int dayOfMonth)
					{
						data.selectdItem(year + "-" + (month + 1) + "-"
								+ dayOfMonth);

					}
				}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
				calendar.get(Calendar.DAY_OF_MONTH));

		return dialog;
	}

	public interface IDialogData
	{
		public void selectdItem(String content);
	}

	public interface IDialogItem
	{
		public void selectdItem(String content);
	}

	public static AlertDialog date(Context context, final String data[],
			final IDialogItem dialogItem)
	{
		Builder dialog = new AlertDialog.Builder(context);
		dialog.setItems(data, new OnClickListener()
		{

			@Override
			public void onClick(DialogInterface arg0, int arg1)
			{
				dialogItem.selectdItem(data[arg1]);
			}
		});
		return dialog.create();
	}

}
